import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:short_drama/pages/home/home.dart';
import 'package:short_drama/pages/main_tabs/main_tab_viewmodel.dart';
import 'package:short_drama/pages/mine/mine.dart';

class MainTabPage extends StatefulWidget {
  const MainTabPage({super.key});

  @override
  State<MainTabPage> createState() => _MainTabPageState();
}

class _MainTabPageState extends State<MainTabPage> {
  MainTabViewModel viewModel = MainTabViewModel();
  static const List<Widget> _contentPages = <Widget>[
    HomePage(),
    PersonalCenterPage(),
  ];
  final PageController _pageController = PageController();

  void _onItemTapped(int index) {
    viewModel.selectedIndex.value = index;
    _pageController.jumpToPage(index);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: PageView(
          controller: _pageController,
          physics: const NeverScrollableScrollPhysics(),
          children: _contentPages,
        ),
      ),
      bottomNavigationBar: Obx(
        () => BottomNavigationBar(
          backgroundColor: Color(0xdd000000),
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon:
                  viewModel.selectedIndex.value == 0
                      ? Image.asset('assets/images/icon_tab_home_sel.png', scale: 3)
                      : Image.asset(
                        'assets/images/icon_tab_home.png',
                        scale: 3,
                      ),
              label: '首页',
            ),
            BottomNavigationBarItem(
              icon:
                  viewModel.selectedIndex.value == 1
                      ? Image.asset('assets/images/icon_tab_mine_sel.png', scale: 3)
                      : Image.asset(
                        'assets/images/icon_tab_mine.png',
                        scale: 3,
                      ),
              label: '个人中心',
            ),
          ],
          currentIndex: viewModel.selectedIndex.value,
          selectedItemColor: Colors.white,
          unselectedItemColor: Colors.grey,
          onTap: _onItemTapped,
        ),
      ),
    );
  }
}
